<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>菜单维护</title>

<link rel="stylesheet" type="text/css" href="../../css/cm-default.css" />
<link rel="stylesheet" type="text/css" href="../../css/main.css" />
<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" />
<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/ligerui-icons.css" />
<link rel="stylesheet" type="text/css" href="../../lib/bootstrap/css/bootstrap.css"/>
<script type="text/javascript" src="../../lib/jquery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../lib/ligerUI/js/ligerui.all.js" ></script>
<script type="text/javascript" src="../../js/common.js" ></script>
<script type="text/javascript" src="../../lib/autoInput/AutoInput.js" ></script>
<script type="text/javascript" src="../../js/pub.js"></script>
<script type="text/javascript" src="../../lib/bootstrap/js/bootstrap.js" ></script>
<script type="text/javascript" src="../../lib/md5.js"></script>
<script type="text/javascript">
    var defGrid;
    var userid;
    $(function(){
        defGrid = $("#query_list").ligerGrid({
            columns:[
                {display:'操作',isSort:false,width:60,render:function(rowdata,rowindex,value) {
                    var h = "";
                    if (!rowdata._editing) {
                        h += "<a href='javascript:void(0);' class='opt-link' onclick='beginEdit(" + rowindex + ")'>修改</a> ";
                        h += "<a href='javascript:void(0);' class='opt-link' onclick='deleteRow(" + rowindex + ")'>删除</a> ";
                    } else {
                        h += "<a href='javascript:void(0);' class='opt-link' onclick='endEdit(" + rowindex + ")'>提交</a> ";
                        h += "<a href='javascript:void(0);' class='opt-link' onclick='cancelEdit(" + rowindex + ")'>取消</a> ";
                    }
                    return h;
                }},
                {display:'编号',name:'code',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                {display:'名称',name:'name',width:80,minWidth:60,align:'left',editor:{type:'text'}},

                {display:'上级菜单编号',name:'higher_id',width:10,minWidth:60,align:'left',editor:{type:'text'}},
                {display:'显示顺序',name:'seq',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                {display:'资源编号',name:'resource_id',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                {display:'图标',name:'icon_uri',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                {display:'提示信息',name:'hint',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                {display:'分级码',name:'path',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                {display:'级数',name:'layer',width:80,minWidth:60,align:'left',editor:{type:'text'}},

                {display:'明细否',name:'detail',width:70,data:getdetail,render:switcher_detail,editor:{type:'select',data:getdetail,textField:'name',valueField:'value',selectBoxHeight:50}},
                {display:'状态',name:'status',width:70,data:status,render:switcher,editor:{type:'select',data:getStatus,textField:'name',valueField:'value',selectBoxHeight:50}},
                {display:'说明',name:'descriptioin',width:200,align:'left',editor:{type:'text'}}
            ],
            pageSize:10,
            usePager: true,
            sortName:'id',
            dataAction:'server',
            sqlid:"rbac.select.def.queryMenu",
            url: '/comm/q',
            contentType : "application/json; charset=utf-8",
            width:'100%',
            height:'99%',
            checkbox:false,
            rownumbers:false,
            fixedCellHeight:false,
            colDraggable:true,
            enabledEdit:true,
            clickToEdit:false,
            onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
            param_status:'rbac.status',
            param_detail:'yesOrNo'

        });
        $("#pageloading").hide();
    });
    function beginEdit(rowid) {
        defGrid.beginEdit(rowid);
    }
    function cancelEdit(rowid) {
        defGrid.cancelEdit(rowid);
    }
    function endEdit(rowid) {
        defGrid.endEdit(rowid);
        var row = defGrid.getRow(rowid);
        toModify(JSON.stringify(row));
    }
    function deleteRow(rowid) {
        $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
            if (!r)
                return;
            var row = defGrid.getRow(rowid);
            if (row['__status'] !== 'add')
                toDel(JSON.stringify(row));
            defGrid.deleteRow(rowid);
        })
    }
    function switcher(item) {
        return paramRender(item, defGrid.options.param_status, item.status);
    }
    var getStatus = new function () {
        return getData('rbac.status');
    }
    function switcher_detail(item) {
        return paramRender(item, defGrid.options.param_detail, item.detail);
    }
    var getdetail = new function () {
        return getData('yesOrNo');
    }
    function toQuery(item, page, pageSize) {
        var param = new Object();
        param.name = $("#name").val();
        param.status = $("#dictStatus").val();
        // l-list 线性结构，默认；t-tree 树型结构
        param.rt='l';
        //重置页码
        defGrid.set({
            page : 1,
            newPage : 1,
            postData : param
        });
        // grid 重新加载数据
        defGrid.loadData();
    }

    var addDialog;
    function openDictDef() {
        toReset('#new_dict_def input,select,textarea');
        addDialog = $.ligerDialog.open({
            target:$("#new_dict_def"),
            title:"新增菜单",
            width:650,
            height:400
        });
    }
    function validate() {
        var valid = true;

        $('*[id$="S"],*[id$="S_txt"]').each(function(index, element) {

            if (!$(this).rules()) return;
            if (!$(element).valid()) {
                valid = false;
                return;
            }
        });
        if (!valid) return false;

        return true
    }
    function toAdd() {
        if (!validate())
        {
            return;
        }
        var param = new Object();
        param.code=$("#newCodeS").val();
        param.name = $("#newNameS").val();
        param.higher_id=$("#newHIGHER_IDS").val();
        param.seq=$("#newSEQ").val();
        param.resource_id=$("#newRESOURCE_IDS").val();
        param.icon_uri=$("#newICON_URI").val();
        param.hint=$("#newHint").val();
        param.path=$("#newPath").val();
        param.layer=$("#newLayer").val();
        param.detail=$("#newDetail").val();
        param.status = $("#newStatus").val();
        param.desc=$("#newDesc").val();
        var data = JSON.stringify(reqJson("rbac.add.def.addMenu",JSON.stringify(param)));
        ajaxSubmit("/comm/a", data, function(data) {
            if (data) {
                if (parseInt(data['status']) > 0) {
                    $.ligerDialog.success('保存成功', '操作完成', function() {
                        addDialog.hide();
                        toQuery();
                    });
                } else {
                    $.ligerDialog.error('保存失败');
                }
            }
        });
    }
    function toModify(row) {
        var data = JSON.stringify(reqJson("rbac.update.def.updateMenu",row));
        ajaxSubmit("/comm/u", data, function(data) {
            if (data) {
                if (parseInt(data['status']) > 0) {
                    $.ligerDialog.success('保存成功');
                } else {
                    $.ligerDialog.error('保存失败');
                }
            }
        });
    }
    function toDel(row) {
        var param = JSON.stringify(reqJson('rbac.delete.def.deleMenu',row));
        ajaxSubmit("/comm/d", param, function(data) {
            if (data) {
                if (parseInt(data['status']) > 0) {
                    $.ligerDialog.success('删除成功');
                } else {
                    $.ligerDialog.error('删除失败');
                }
            }
        });
    }
</script>
<style type="text/css">
.label-div {width:19%;height:25px;position:relative;float:left;padding:5px 0 0 0;}
.in-div {width:31%;height:25px;position:relative;float:left;padding: 5px 0 0 0;}
</style>
</head>
<body style="padding:0;">
<div id="pageloading"></div>
<div id="layout_main">
    <div position="center" id="a_center" title="菜单列表">
        <div id="query_cond" class="fields">
        	<div style="padding-left:15px;padding-top:5px;">
 			<button type="button" onclick="openDictDef();" class="btn btn-primary btn-xs ">
   				&nbsp;<span class="glyphicon glyphicon-plus">新增</span>
    		</button>
   			</div>
   			
            <label>名称</label><input type="text" class="s-text txt-def" id="name" />
            <label>状态</label><select id="dictStatus" param="rbac.status" first=""></select>
            <button type="button" onclick="toQuery();" style="margin-left:25px;" class="form_Button btn btn-primary btn-xs">查询</button>
            <button type="button" onclick="toReset('#query_cond input,select,textarea');" class="form_Button btn btn-primary btn-xs">清空</button>
        </div>
        <div id="query_list"></div>
    </div>
</div>
<div id="new_dict_def" style="display:none;overflow:hidden;">
    <form name="basic-form" method="post" id="basic_form" class="liger-form" data-validate="{}">
        <div class="line-div">
            <div class="label-div"><label>编号</label></div>
            <div class="in-div"><input type="text" ltype="text" class="required s-text txt-def" id="newCodeS" /></div>

            <div class="label-div"><label>名称</label></div>
            <div class="in-div"><input type="text" ltype="text" class="required s-text txt-def" id="newNameS" /></div>
        </div>
        <div class="line-div">
            <div class="label-div"><label>上级菜单编号</label></div>
            <div class="in-div"><input type="text"  ltype="text" class="required s-text txt-def" id="newHIGHER_IDS" /></div>

            <div class="label-div"><label>显示顺序</label></div>
            <div class="in-div"><input type="text" class="s-text txt-def" id="newSEQ" /></div>
        </div>
        <div class="line-div">
            <div class="label-div"><label>资源编号</label></div>
            <div class="in-div"><input type="text" ltype="text" class="required s-text txt-def" id="newRESOURCE_IDS" /></div>

            <div class="label-div"><label>图标</label></div>
            <div class="in-div"><input type="text" class="s-text txt-def" id="newICON_URI" /></div>
        </div>
   
    <div class="line-div">
        <div class="label-div"><label>提示信息</label></div>
        <div class="in-div"><input type="text" class="s-text txt-def" id="newHint" /></div>

        <div class="label-div"><label>分级码</label></div>
        <div class="in-div"><input type="text" class="s-text txt-def" id="newPath" /></div>
    </div>
    <div class="line-div">
        <div class="label-div"><label>级数</label></div>
        <div class="in-div"><input type="text" class="s-text txt-def" id="newLayer" /></div>

        <div class="label-div"><label>明细否</label></div>
        <div class="in-div">
            <select class="txt-def" id="newDetail" param="yesOrNo" default="1" style="margin-right: 30px;"></select>
        </div>
    </div>
    <div class="line-div">
        <div class="label-div"><label>状态</label></div>
        <div class="in-div"><select class="txt-def" id="newStatus" param="rbac.status" default="1" style="margin-right: 30px;"></select></div>
    </div>
    <div class="line-div">
        <div class="label-div"><label>说明</label></div>
        <div class="in-div"><textarea cols="24" rows="2" id="newDesc"></textarea></div>
    </div>
    <div class="line-div" style="margin-top:50px;padding-left:40%;">
        <button type="button" onclick="toAdd();" class="form_Button btn btn-primary btn-xs">保存</button>
    	<button type="button" onclick="toReset('#up_dict_pw input,select,textarea')" class="form_Button btn btn-primary btn-xs">清空</button>
    </div>
     </form>
</div>

</body>
</html>